// TypeScript的引用数据类型（数组、函数、对象）

/* (1)数组 => 变量名：数据类型 [] */
let arr1: string[] = ["Vue3", "Spring Boot", "MySQL"]
let arr2: number[] = [95, 98, 92]
// 联合类型：可以在数据类型中，通过 ‘|’ 进行联合
let arr3: (string | number)[] = ["前端", 95, "后端", 98]

console.log("数组类型演示:")
console.log(' ',arr1,'\n ',arr2,'\n ',arr3,'\n')


/* (2)对象 =>  */
// 1.变量名：object = {} (不常用)
let obj1:object ={
    name:'Mary',
    age:18
}
// 2.接口 -> 对象  [注意：接口和对象的属性一致,但是可以在属性后加'？'变成可选属性]
interface obj2{
    name:string,
    age:number,
    height?:number
}

let obj3:obj2 = {
    name:'Mark',
    age:20
}

let obj4:obj2 ={
    name:'Amy',
    age:19,
    height:175
}

let obj5:{name:string,age:number,height?:number}={
    name:'Jhon',
    age:14,
    height:180
}

console.log("对象类型演示:")
console.log(' ',obj1,'\n ',obj3,'\n ',obj4,'\n ',obj5,'\n')


/* 联合类型 */
let lh1:(string|number|boolean)[] = ['zh',234,true]
console.log("联合数组：",lh1)

let lh2:string|number|boolean = 56
console.log("联合变量：",lh2)
lh2 = 'zhe'
console.log("联合变量：",lh2,'\n')


/* 字面量类型 */
let p1:'zs' = 'zs'  // p1只能等于‘zs’
console.log("字面量类型1：",p1)

let p2:55|99 = 55  // p2等于55或者99
console.log("字面量类型2：",p2)
p2 = 99
console.log("字面量类型2：",p2)
// p2 = 45  编译错误

let p3:55|string = 55
console.log("字面量类型3：",p3)
p3 = 'zhw'
console.log("字面量类型3：",p3,'\n')






